#include "Reactor.hpp"
#include "Listener.hpp"
#include "IOService.hpp"
#include "Package.hpp"

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        return 0;
    }
    uint16_t port = std::stoi(argv[1]);

    IOService ioservice(Package::Parse);
    ListenSock listener(ioservice, port);

    unique_ptr<Reactor> ptr = make_unique<Reactor>();

    ptr->AddConnection( listener.getfd(),
                        EPOLLIN | EPOLLET, 
                        bind(&ListenSock::Accepter, &listener, placeholders::_1), 
                        nullptr, 
                        nullptr);
    
    int timeout = 3000;
    ptr->Dispatcher(timeout);

    return 0;
}